package docsim;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.WritableComparable;

public class DocumentCount implements WritableComparable{
	int docID;
	int count;
	
	public void set(int did, int c) {
		docID = did;
		count = c;
	}

	@Override
	public void readFields(DataInput arg0) throws IOException {
		docID = arg0.readInt();
		count = arg0.readInt();
	}
	@Override
	public void write(DataOutput arg0) throws IOException {
		arg0.writeInt(docID);
		arg0.writeInt(count);
	}
	
	@Override
	public int hashCode() {
		return (docID ^ count);
	};
	
	@Override
	public boolean equals(Object obj) {
		return (obj instanceof DocumentCount
				&& ((DocumentCount) obj).docID == this.docID && ((DocumentCount) obj).count == this.count);
	};
	
	@Override
	public int compareTo(Object o) {
		if(docID!=((DocumentCount)o).docID)
		{
			return (docID - ((DocumentCount)o).docID);
		}
		else
		{
			return (count - ((DocumentCount)o).count);
		}
	}
}
